<!DOCTYPE html>

<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/jquery.jqGrid.min.js"></script>
    <!-- A link to a Boostrap  and jqGrid Bootstrap CSS siles-->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid-bootstrap.css" />
	<script>
		$.jgrid.defaults.width = 780;
		$.jgrid.defaults.responsive = true;
		$.jgrid.defaults.styleUI = 'Bootstrap';
	</script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Dialogs - Inline Validation Client Side</title>
</head>
<body>
<div style="margin-left:20px">
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>
    <script type="text/javascript">
        $(document).ready(function () {
			if (!window.console) window.console = {};
			if (!window.console.log) window.console.log = function () { };

			$("#jqGrid").jqGrid({
                url: 'data.json',
                editurl: 'clientArray',
                datatype: "json",
                colModel: [
                    {
                        name: 'Integer',
                        key: true,
                        editable: true,
                        editrules:{
							//custom rules
                            custom_func: validatePositive,
                            custom: true,
                            required: true
                        },
                        width: 75
                    },
                    {
                        name: 'Number',
                        width: 100,
                        editable: true,
                        editrules: {
							number: true,
                            minValue: 1000,
                            maxValue: 10000,
                            required: true
                        }
                    },
                    {
                        name: 'Email',
                        width: 100,
                        editable: true,
                        editrules: {
                            email: true,
                            required: true
                        }
                    },
                    {
                        name: 'Url',
                        width: 80,
                        editable: true,
                        editrules: {
                            url: true,
                            required: true
                        }
                    }
                ],
				loadonce : true,
                onSelectRow: editRow,
                width: 780,
                height: 200,
                rowNum: 10,
                pager: "#jqGridPager"
        });

        var lastSelection;

        function editRow(id) {
            if (id && id !== lastSelection) {
                var grid = $("#jqGrid");
                grid.jqGrid('restoreRow',lastSelection);

                var editParameters = {
                    keys: true,
                    successfunc: editSuccessful,
                    errorfunc: editFailed
                };

                grid.jqGrid('editRow',id, editParameters);
                lastSelection = id;
            }
        }

        function editSuccessful() {
            console.log("success");
        }

        function editFailed() {
            console.log("fail");
        }

        function validatePositive(value, column) {
            if ( isNaN(value) && value < 0)
                return [false, "Please enter a positive value or correct value"];
            else
                return [true, ""];
        }                
    });

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="margin-left:18px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="width:700px; height: 400px; font-size:65%;"></div>
     
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
        <script type="text/ecmascript" src="../../../js/codetabs-b.js"></script> 
    
    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
                { name: "Data", url: "data.json", lang: "lang-json" },
				{ name: "Description", url: "description.html", lang: "lang-html" }
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>